﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using Alimentador.Foods;

namespace Alimentador.BottomGroup.Results
{
    /// <summary>
    /// Interaction logic for GraphicResults.xaml
    /// </summary>
    public partial class GraphicResults : UserControl
    {
        private List<FoodProperty> m_valueList = new List<FoodProperty>();
        private List<FoodBase> m_foodList = new List<FoodBase>();
        private int m_numDays = 1;

        public GraphicResults()
        {
            InitializeComponent();

            RefreshCharts();

            //EnergyPieChart   
            //FatAcidsPieChart
            //MineralsColumnChart
            //VitaminsColumnChart
        }

        /// <summary>
        /// Refresh all chart data
        /// </summary>
        private void RefreshCharts()
        {
            EnergyPieChart.AddFood(m_foodList, m_numDays);
            FatAcidsPieChart.AddFood(m_foodList, m_numDays);
            MineralsColumnChart.AddFood(m_foodList, m_numDays);
            VitaminsColumnChart.AddFood(m_foodList, m_numDays);
        }

        /// <summary>
        /// Hanlde the event for adding a Food to list
        /// </summary>
        /// <param name="foodList">List(Food)</param>
        /// <param name="numDays">int</param>
        internal void AddFood(List<FoodBase> foodList, int numDays = 1)
        {
            m_foodList = foodList;
            m_numDays = numDays;
            RefreshCharts();
        }

        private void RadioBtn_Click(object sender, RoutedEventArgs e)
        {
            EnergyRBtn.IsChecked = false;
            FatAcidsRBtn.IsChecked = false;
            MineralsRBtn.IsChecked = false;
            VitaminsRBtn.IsChecked = false;

            ToggleButton rb = (ToggleButton)sender;
            rb.IsChecked = true;

            if (rb != null)
            {
                EnergyPieChart.Visibility =
                    FatAcidsPieChart.Visibility =
                    MineralsColumnChart.Visibility =
                    VitaminsColumnChart.Visibility = System.Windows.Visibility.Collapsed;

                if (rb.Name == "EnergyRBtn")
                {
                    EnergyPieChart.Visibility = System.Windows.Visibility.Visible;
                }
                else if (rb.Name == "MineralsRBtn")
                {
                    MineralsColumnChart.Visibility = System.Windows.Visibility.Visible;
                }
                else if (rb.Name == "FatAcidsRBtn")
                {
                    FatAcidsPieChart.Visibility = System.Windows.Visibility.Visible;
                }
                else if (rb.Name == "VitaminsRBtn")
                {
                    VitaminsColumnChart.Visibility = System.Windows.Visibility.Visible;
                }
            }
        }
    }
}
